package etcd

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/balancer/roundrobin"
	"google.golang.org/grpc/resolver"

)

func NewClient(addrs []string, key string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
	options := []grpc.DialOption{
		grpc.WithInsecure(),
		grpc.WithBalancerName(roundrobin.Name),
	}
	options = append(options, opts...)

	r := NewResolver(addrs)
	resolver.Register(r)

	tagert := BuildDiscovTarget(addrs, key)
	conn, err := grpc.Dial(tagert, options...)
	if err != nil {
		return nil, err
	}
	return conn, nil
}